home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / CustomWriterGX / OldApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  7.4 KB  |  239 lines  |  [TEXT/MPS ]

  1. /*
  2.     FILENAME
  3.         OldApp.c
  4.  
  5.     DESCRIPTION
  6.         Contains code for our old-application message overrides.
  7.  
  8.     COPYRIGHT
  9.         Copyright © 1995 Apple Computer, Inc.
  10.         All rights reserved.
  11.     
  12.     Modification history
  13.         10/04/95 - David Hayward -    Version 1.0.4 modified code so that
  14.                                     the driver can be build under MPW,
  15.                                     Metrowerks, and Symantec.  In general,
  16.                                     all that was required to do this was 
  17.                                     to add an inline-assembly jumptable
  18.                                     and to store all globals off of the
  19.                                     message manager instance context.
  20.                                     Also made a few changes so that the
  21.                                     driver can be rebuilt to support any
  22.                                     resolution by changing the #defines
  23.                                     kResolution and kPatStretch in
  24.                                     "CommonDefines.h"
  25.  
  26.         06/14/95 - Dave Hersey -    Version 1.0.3 to fix a bug in
  27.                                     CustomBufferingAndIO.c when creating
  28.                                     high-res PICTs, and to make the size
  29.                                     of buffers more flexible.
  30.  
  31.         05/26/95 - Dave Hersey -    Version 1.0.2 to add the new 'outp'
  32.                                     desktop printer resource in NewApp.c.
  33.  
  34.         05/03/95 - Dave Hersey -    Version 1.0.1 to fix some minor bugs in
  35.                                     CustomBufferingAndIO.c.
  36.  
  37.         01/14/95 - Dave Hersey -    Created from the shell of a hollowed-out
  38.                                     ImageWriter driver.
  39. */
  40.  
  41.  
  42. #include <Types.h>
  43. #include <GXPrinterDrivers.h>
  44. #include <GXPrinting.h>
  45.  
  46.  
  47. // Defines used by the old-application compatibility code.
  48. #define kPortrait                (0x04)
  49. #define kPrintRecordVers        (12)
  50. #define kDriverWDev                (0x8800)
  51.  
  52.  
  53. // Prototypes for local functions.
  54. OSErr    SD_ConvertPrintRecordFrom    ( gxUniversalPrintRecordHdl huPrint ) ;
  55. OSErr    SD_ConvertPrintRecordTo        ( THPrint hoPrint ) ;
  56. OSErr    SD_PrValidate                ( THPrint hPrint, Boolean *wasChanged ) ;
  57. OSErr    UpdatePrintRecord            ( THPrint hPrint ) ;
  58.  
  59.  
  60. /*    -----------------------------------------------------------------------
  61.  
  62.     __Startup__ contains our jump table to the overrides.
  63.     This code must be kept in sync with the assembly jump table
  64.     in OldTable.a and the gxOverrideType resource in OldTable.r
  65.  
  66.     -----------------------------------------------------------------------    */
  67.  
  68. #if defined(__MWERKS__)
  69. asm void __Startup__(void);
  70. asm void __Startup__(void)
  71. {
  72.     DC.L    0                    // Reserved for owner count.
  73.  
  74.     JMP        SD_ConvertPrintRecordTo        // (offset =  4)
  75.     JMP        SD_ConvertPrintRecordFrom    // (offset =  8)
  76.     JMP        SD_PrValidate                // (offset = 12)
  77.  
  78.     RTS                            // this is needed so __Startup__ symbol works
  79. }
  80. #endif
  81.  
  82.  
  83. /*    -----------------------------------------------------------------------
  84.  
  85.     SD_ConvertPrintRecordTo is an override of gxConvertPrintRecordTo.  It
  86.     takes a print record in old style (driver specific) format, and converts
  87.     it to the format of gxUniversalPrintRecordHdl.  Since we don't have an
  88.     "old-style" format we need to support, there's not much we need to do
  89.     here.
  90.  
  91.     -----------------------------------------------------------------------    */
  92.  
  93. OSErr SD_ConvertPrintRecordTo(THPrint hoPrint)
  94. {
  95.     TPPrint                        poPrint;            // pointer to old style print record
  96.     gxUniversalPrintRecordHdl    huPrint = (gxUniversalPrintRecordHdl) hoPrint;    // handle to universal print record
  97.     gxUniversalPrintRecordPtr    puPrint;            // pointer to universal print record
  98.     short                        wDev;                // cached wDev
  99.  
  100.     puPrint = *huPrint;
  101.     poPrint = *hoPrint;
  102.  
  103.     // We always print at our best resolution, and autofeed at 100% scaling.
  104.  
  105.     puPrint->qualityMode = gxBestQuality;
  106.     puPrint->feed =    true;
  107.     puPrint->reduction = 100;
  108.  
  109.     // Save our orientation and copies settings.
  110.     wDev = poPrint->prStl.wDev;
  111.     puPrint->orientation = (wDev & kPortrait)?    gxPortraitOrientation: gxLandscapeOrientation;
  112.     puPrint->actualCopies =    poPrint->prJob.iCopies;
  113.     puPrint->options = 0;
  114.         
  115.     return noErr;
  116. }
  117.  
  118.  
  119. /*    -----------------------------------------------------------------------
  120.  
  121.     SD_ConvertPrintRecordFrom is an override for gxConvertPrintRecordFrom.
  122.     It takes a print record in universal format and converts it to old
  123.     style (driver specific) format.  Since we don't have an "old-style"
  124.     format we need to support, there's not much we need to do here.
  125.  
  126.     -----------------------------------------------------------------------    */
  127.  
  128. OSErr SD_ConvertPrintRecordFrom(gxUniversalPrintRecordHdl huPrint)
  129. {
  130.     gxUniversalPrintRecordPtr    puPrint;            // pointer to universal print record
  131.     THPrint                        hoPrint = (THPrint) huPrint;    // handle to old style print record
  132.     TPPrint                        poPrint;            // pointer to old style print record
  133.     short                        wDev;                // workspace to create our wDev value
  134.  
  135.     // Cache pointers for size and speed
  136.     puPrint = *huPrint;
  137.     poPrint = *hoPrint;
  138.  
  139.     // Convert various fields of our print record, starting with the wDev.
  140.     
  141.     // This is our base wDev value-- note I was bad and didn't register this
  142.     // with DEVSUPPORT.  You should.
  143.  
  144.     wDev = kDriverWDev;
  145.     
  146.     if (puPrint->orientation == gxPortraitOrientation)
  147.         wDev |= kPortrait;
  148.  
  149.     poPrint->prStl.wDev            = wDev;
  150.     poPrint->iPrVersion            = kPrintRecordVers;
  151.     poPrint->prInfo.iDev        = 0;
  152.     poPrint->prInfoPT.iDev         = 0;
  153.     poPrint->prStl.bPort         = 0;
  154.     poPrint->prStl.feed         = false;
  155.     poPrint->prJob.iCopies        = puPrint->actualCopies;
  156.     poPrint->prJob.bJDocLoop    = 1;
  157.     
  158.     // This routine is so studly, there can be no errors
  159.     return noErr;    
  160. }
  161.  
  162.  
  163. /*    -----------------------------------------------------------------------
  164.  
  165.     SD_PrValidate is an override of gxPrValidate.  It validates the current
  166.     print record.  It's fairly simplistic--if the wDev or versions don't
  167.     match ours, we call PrintDefault.  Otherwise, we call UpdatePrintRecord
  168.     to allow the driver to sanity check any internal fields.
  169.  
  170.     -----------------------------------------------------------------------    */
  171.  
  172. OSErr SD_PrValidate(THPrint hPrint,         // old style print record
  173.                     Boolean *wasChanged)    // was the print record changed?
  174. {
  175.     unsigned short    wDev;
  176.     Boolean            recordIsInvalid = true;            
  177.     OSErr            anErr = noErr;
  178.  
  179.     // Check the wDev.  The upper byte must be equal to our wDev
  180.         
  181.     wDev = (*hPrint)->prStl.wDev;    
  182.     wDev >>= 8;                        // Get just the device ID
  183.  
  184.     // If the device id is equal to ours, check the version number of the print record.
  185.     // Only if that is also equal to the current version, will we return false (valid).
  186.         
  187.     if ((wDev == (kDriverWDev >> 8)) && ((((*hPrint)->iPrVersion) == kPrintRecordVers)))
  188.         recordIsInvalid = false;
  189.  
  190.     // If the print record is not valid, then call PrintDefault so
  191.     // that QuickDraw GX loads our default print record from 'PREC' 0.
  192.     // Otherwise, do the final sanity check/reset of our print record.
  193.         
  194.     if (recordIsInvalid)
  195.         PrintDefault(hPrint);
  196.     else
  197.         anErr = UpdatePrintRecord(hPrint);
  198.         
  199.     *wasChanged = recordIsInvalid;
  200.     return (anErr);
  201. }
  202.  
  203.  
  204. /*    -----------------------------------------------------------------------
  205.  
  206.     UpdatePrintRecord is called by SD_PrValidate.  It simply does a sanity
  207.     check (and reset) of the volatile fields of our old style print records.
  208.  
  209.     -----------------------------------------------------------------------    */
  210.  
  211. OSErr UpdatePrintRecord(THPrint hPrint)
  212. {
  213.     OSErr                        anErr;
  214.     gxUniversalPrintRecordHdl     huPrint = (gxUniversalPrintRecordHdl) hPrint;
  215.     gxUniversalPrintRecordPtr     puPrint;
  216.  
  217.     // Convert the print record to universal format.  If there are
  218.     // no errors, store the resolution, and convert the print
  219.     // record back to non-universal format.
  220.  
  221.     anErr = SD_ConvertPrintRecordTo(hPrint);
  222.  
  223.     if (anErr == noErr)
  224.     {
  225.         puPrint = *huPrint;
  226.  
  227.         // Default the app & device resolutions
  228.         puPrint->devVRes =
  229.         puPrint->devHRes =
  230.         puPrint->appVRes =
  231.         puPrint->appHRes = 72;
  232.         
  233.         // Convert back to non-universal format
  234.         anErr = SD_ConvertPrintRecordFrom((gxUniversalPrintRecordHdl) hPrint);
  235.     }
  236.         
  237.     return anErr;
  238. }
  239.